package cn.meibang.common.beauty.provider.dao;

import cn.meibang.common.beauty.provider.domain.BeautyConsultationOrderUser;
import cn.meibang.common.beauty.provider.request.ListOrderUserRequest;

import static org.apache.ibatis.jdbc.SqlBuilder.*;

public class BeautyConsultationOrderUserSqlProvider {

    public String selectByListRequest(ListOrderUserRequest request) {
        StringBuilder sqlSb = new StringBuilder();
        sqlSb.append("select id, tag, user_id, openid, store_id, consultant_id, title, order_id, create_by, create_date, is_deal, deal_date ");
        sqlSb.append("from beauty_consultation_order_user ");
        sqlSb.append("where 1 = 1 ");
        sqlSb.append("and consultant_id = #{userId} ");
        if (request.getStartDate() != null) {
            sqlSb.append("and create_date >= #{startDate} ");
        }
        if (request.getEndDate() != null) {
            sqlSb.append("and create_date <= #{endDate} ");
        }
        sqlSb.append("order by id desc ");
        sqlSb.append("limit #{offset}, #{size} ");
        return sqlSb.toString();
    }

    public String insertSelective(BeautyConsultationOrderUser record) {
        BEGIN();
        INSERT_INTO("beauty_consultation_order_user");

        if (record.getId() != null) {
            VALUES("id", "#{id,jdbcType=BIGINT}");
        }

        if (record.getTag() != null) {
            VALUES("tag", "#{tag,jdbcType=VARCHAR}");
        }

        if (record.getStoreId() != null) {
            VALUES("store_id", "#{storeId}");
        }

        if (record.getUserId() != null) {
            VALUES("user_id", "#{userId}");
        }

        if (record.getOpenid() != null) {
            VALUES("openid", "#{openid}");
        }

        if (record.getConsultantId() != null) {
            VALUES("consultant_id", "#{consultantId,jdbcType=BIGINT}");
        }

        if (record.getTitle() != null) {
            VALUES("title", "#{title,jdbcType=VARCHAR}");
        }

        if (record.getOrderId() != null) {
            VALUES("order_id", "#{orderId,jdbcType=BIGINT}");
        }

        if (record.getOrderType() != null) {
            VALUES("order_type", "#{orderType,jdbcType=VARCHAR}");
        }

        if (record.getCreateBy() != null) {
            VALUES("create_by", "#{createBy,jdbcType=BIGINT}");
        }

        if (record.getCreateDate() != null) {
            VALUES("create_date", "#{createDate,jdbcType=TIMESTAMP}");
        }

        if (record.getIsDeal() != null) {
            VALUES("is_deal", "#{isDeal}");
        }

        if (record.getDealDate() != null) {
            VALUES("deal_date", "#{dealDate}");
        }

        return SQL();
    }

    public String updateByPrimaryKeySelective(BeautyConsultationOrderUser record) {
        BEGIN();
        UPDATE("beauty_consultation_order_user");

        if (record.getTag() != null) {
            SET("tag = #{tag,jdbcType=VARCHAR}");
        }

        if (record.getStoreId() != null) {
            SET("store_id = #{storeId}");
        }

        if (record.getUserId() != null) {
            SET("user_id = #{userId}");
        }

        if (record.getOpenid() != null) {
            SET("openid = #{openid}");
        }

        if (record.getConsultantId() != null) {
            SET("consultant_id = #{consultantId,jdbcType=BIGINT}");
        }

        if (record.getTitle() != null) {
            SET("title = #{title,jdbcType=VARCHAR}");
        }

        if (record.getOrderId() != null) {
            SET("order_id = #{orderId,jdbcType=BIGINT}");
        }

        if (record.getOrderType() != null) {
            SET("order_type = #{orderType,jdbcType=VARCHAR}");
        }

        if (record.getCreateBy() != null) {
            SET("create_by = #{createBy,jdbcType=BIGINT}");
        }

        if (record.getCreateDate() != null) {
            SET("create_date = #{createDate,jdbcType=TIMESTAMP}");
        }

        if (record.getIsDeal() != null) {
            SET("is_deal = #{isDeal}");
        }

        if (record.getDealDate() != null) {
            SET("deal_date = #{dealDate}");
        }

        WHERE("id = #{id,jdbcType=BIGINT}");

        return SQL();
    }
}